//
//package com.jf.cloud.distribution.listener;
//
//import cn.hutool.core.collection.CollUtil;
//import com.jf.cloud.api.multishop.bo.ShopWalletBO;
//import com.jf.cloud.common.exception.LuckException;
//import com.jf.cloud.common.order.vo.OrderItemVO;
//import com.jf.cloud.common.response.ResponseEnum;
//import com.jf.cloud.common.rocketmq.config.RocketMqConstant;
//import com.jf.cloud.common.util.Json;
//import com.jf.cloud.distribution.bo.DistributionNotifyOrderAndShopBO;
//import org.apache.rocketmq.client.producer.SendStatus;
//import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
//import org.apache.rocketmq.spring.core.RocketMQListener;
//import org.apache.rocketmq.spring.core.RocketMQTemplate;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.messaging.support.GenericMessage;
//import org.springframework.stereotype.Component;
//
//import java.util.List;
//import java.util.Objects;
//
///**
// * 订单支付成功，分销通知
// * @author zz
// * @date 2021-08-17 17:42:17
// */
//@Component
//@RocketMQMessageListener(topic = RocketMqConstant.DISTRIBUTION_NOTIFY_ORDER_SHOP_TOPIC,consumerGroup = RocketMqConstant.DISTRIBUTION_NOTIFY_ORDER_SHOP_TOPIC)
//public class DistributionNotifyOrderShopConsumer implements RocketMQListener<DistributionNotifyOrderAndShopBO> {
//
//    @Autowired
//    private RocketMQTemplate distributionNotifyShopTemplate;
//    @Autowired
//    private RocketMQTemplate distributionNotifyOrderTemplate;
//
//    private static final Logger LOG = LoggerFactory.getLogger(DistributionNotifyOrderShopConsumer.class);
//
//    /**
//     * 分销完成，通知订单和店铺修改订单项分销金额和店铺店铺待结算金额
//     */
//    @Override
//    public void onMessage(DistributionNotifyOrderAndShopBO message) {
//        LOG.info("分销金额计算完成后回调开始... message: " + Json.toJsonString(message));
//
//        // 通知修改店铺钱包待结算金额 DistributionNotifyShopConsumer
//        List<ShopWalletBO> shopWalletBOList = message.getShopWalletBOList();
//        if (CollUtil.isNotEmpty(shopWalletBOList)) {
//            // 发送消息， 通知店铺修改店铺钱包待结算金额
//            SendStatus sendStockStatus = distributionNotifyShopTemplate.syncSend(RocketMqConstant.DISTRIBUTION_NOTIFY_SHOP_TOPIC, new GenericMessage<>(shopWalletBOList)).getSendStatus();
//            if (!Objects.equals(sendStockStatus,SendStatus.SEND_OK)) {
//                throw new LuckException(ResponseEnum.EXCEPTION);
//            }
//        }
//
//        // 通知修改订单项分销金额 DistributionNotifyOrderConsumer
//        List<OrderItemVO> distributionOrderItems = message.getDistributionOrderItems();
//        if (CollUtil.isNotEmpty(distributionOrderItems)) {
//            // 发送消息， 通知修改订单项分销金额
//            SendStatus sendStockStatus = distributionNotifyOrderTemplate.syncSend(RocketMqConstant.DISTRIBUTION_NOTIFY_ORDER_TOPIC, new GenericMessage<>(distributionOrderItems)).getSendStatus();
//            if (!Objects.equals(sendStockStatus,SendStatus.SEND_OK)) {
//                throw new LuckException(ResponseEnum.EXCEPTION);
//            }
//        }
//    }
//}
